package com.hospital.register.model.user;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.hospital.register.constants.RegexConstants;
import com.hospital.register.model.base.BaseEntity;
import com.hospital.register.validation.groups.InsertValidation;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.*;
import java.util.Date;

@Data
@ApiModel(description = "就诊人信息")
@TableName("patient")
public class Patient extends BaseEntity {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "用户id")
    @TableField("user_id")
    private Long userId;

    @ApiModelProperty(value = "姓名")
    @TableField("name")
    @NotBlank(message = "姓名不可为空", groups = InsertValidation.class)
    private String name;

    @ApiModelProperty(value = "证件类型")
    @TableField("certificates_type")
    @NotBlank(message = "证件类型不可为空", groups = InsertValidation.class)
    @Pattern(message = "证件类型错误，10表示身份证，20表示户口本", regexp = "^[1-2]0$", groups = InsertValidation.class)
    private String certificatesType;

    @ApiModelProperty(value = "证件编号")
    @TableField("certificates_no")
    @NotBlank(message = "证件编号不可为空", groups = InsertValidation.class)
    private String certificatesNo;

    @ApiModelProperty(value = "性别")
    @TableField("sex")
    @NotNull(message = "性别不可为空", groups = InsertValidation.class)
    @Range(min = 0L, max = 1L, message = "性别的值只能为0 或 1", groups = InsertValidation.class)
    private Byte sex;

    @ApiModelProperty(value = "出生年月")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @TableField("birthdate")
    @NotNull(message = "出生日期不可为空", groups = InsertValidation.class)
    @Past(message = "出生日期必须早于当前时间", groups = InsertValidation.class)
    private Date birthdate;

    @ApiModelProperty(value = "手机")
    @TableField("phone")
    @NotBlank(message = "就诊人的手机号不可为空", groups = InsertValidation.class)
    @Pattern(regexp = RegexConstants.PHONE, message = "必须是11位手机号", groups = InsertValidation.class)
    private String phone;

    @ApiModelProperty(value = "是否结婚")
    @TableField("is_marry")
    @NotNull(message = "婚否不可为空", groups = InsertValidation.class)
    @Range(min = 0L, max = 1L, message = "婚否的取值必须是 0 或 1", groups = InsertValidation.class)
    private Byte isMarry;

    @ApiModelProperty(value = "省code")
    @TableField("province_code")
    @NotBlank(message = "就诊人所在省的编号不可为空", groups = InsertValidation.class)
    private String provinceCode;

    @ApiModelProperty(value = "市code")
    @TableField("city_code")
    @NotBlank(message = "就诊人所在市的编号不可为空", groups = InsertValidation.class)
    private String cityCode;

    @ApiModelProperty(value = "区code")
    @TableField("district_code")
    @NotBlank(message = "就诊人所在区的编号不可为空", groups = InsertValidation.class)
    private String districtCode;

    @ApiModelProperty(value = "详情地址")
    @TableField("address")
    @NotBlank(message = "就诊人的详情地址不可为空", groups = InsertValidation.class)
    private String address;

    @ApiModelProperty(value = "联系人姓名")
    @TableField("contacts_name")
//    @NotBlank(message = "联系人的姓名不可为空", groups = InsertValidation.class)
    private String contactsName;

    @ApiModelProperty(value = "联系人证件类型")
    @TableField("contacts_certificates_type")
//    @NotBlank(message = "联系人的证件类型不可为空", groups = InsertValidation.class)
//    @Pattern(message = "证件类型错误，10表示身份证，20表示户口本", regexp = "^[1-2]0$")
    private String contactsCertificatesType;

    @ApiModelProperty(value = "联系人证件号")
    @TableField("contacts_certificates_no")
//    @NotBlank(message = "联系人的证件号不可为空", groups = InsertValidation.class)
    private String contactsCertificatesNo;

    @ApiModelProperty(value = "联系人手机")
    @TableField("contacts_phone")
//    @NotBlank(message = "联系人的手机号不可为空", groups = InsertValidation.class)
//    @Pattern(regexp = RegexConstants.PHONE, message = "必须是11位手机号", groups = InsertValidation.class)
    private String contactsPhone;

    @ApiModelProperty(value = "是否有医保")
    @TableField("is_insure")
    @NotNull(message = "是否有医保不可省略", groups = InsertValidation.class)
    @Range(min = 0L, max = 1L, message = "是否有医保的取值必须为 0 或 1", groups = InsertValidation.class)
    private Byte isInsure;

    @ApiModelProperty(value = "就诊卡")
    @TableField("card_no")
//    @NotBlank(message = "就诊卡号不可为空", groups = InsertValidation.class)
    private String cardNo;

    @ApiModelProperty(value = "状态（0：默认 1：已认证）")
    @TableField("status")
    @Null(message = "只有管理员才能修改就诊人的状态", groups = InsertValidation.class)
    private Byte status;
}

